package ducna.misscall.screen.misscall;
/**
 * @author DUCNA
 */
import java.util.ArrayList;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;
import ducna.alozo.misscall.R;
import ducna.misscall.common.model.ContactMiss;
import ducna.misscall.comon.fragment.BaseFragment;
import ducna.misscall.screen.misscall.adapter.ListMissCallAdapter;
import ducna.misscall.utils.Logger;

public class MissCallFragment extends BaseFragment implements OnItemClickListener{
	private String TAG = MissCallFragment.class.getSimpleName();
	private EditText mEditTextSearch;
	private ListView mListViewContactMiss;
	
	private ListMissCallAdapter mAdapter;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_miss_call, container, false);
		
		mEditTextSearch = (EditText) view.findViewById(R.id.editTextSearch);
		mListViewContactMiss = (ListView) view.findViewById(R.id.listViewMissCall);
		mListViewContactMiss.setOnItemClickListener(this);
		mAdapter = new ListMissCallAdapter(getActivity());
		mAdapter.setListContactMiss(createSimpleData());
		
		mListViewContactMiss.setAdapter(mAdapter);
		return view;
	}
	
	public ArrayList<ContactMiss> createSimpleData(){
		ArrayList<ContactMiss> data = new ArrayList<ContactMiss>();
		
		for (int i = 0; i < 20; i++) {
			ContactMiss contact = new ContactMiss();
			contact.setName("Nguyen Anh Duc");
			contact.setLastDate("15/12/2014");
			contact.setLastTime("12:12");
			contact.setNumberMiss(10);
			data.add(contact);
		}
		Logger.out(TAG, "data size : " + data.size());
		return data;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//		Logger.out(TAG, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
//		addFragment(new DetailMissCallFragment(), android.R.id.content);
//		FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
//		transaction.add(new DetailMissCallFragment(), TAG);
//		transaction.addToBackStack(TAG);
//		transaction.commit();
		Logger.out(TAG, "" + getParentFragment());
		((MainMissCallFragment) getParentFragment()).goDetail(id);
	}
}
